#include <func.h>

#define MAXSIZE 1024

int main(void)
{
    int fields_1[2];
    if(pipe(fields_1) == -1)
        error(1, errno, "pipe");
    int fields_2[2];
    if(pipe(fields_2) == -1)
        error(1, errno, "pipe");
   char buffer[MAXSIZE];
    pid_t pid = fork();
    switch(pid)
    {
    case -1:
        error(1, errno, "fork");
    case 0:
        close(fields_1[0]);
        close(fields_2[1]);
        write(fields_1[1], "hello father\n", 13 +1);
        read(fields_2[0], buffer, MAXSIZE);
        printf("from father: %s\n", buffer);
        break;
    default:
        close(fields_1[1]);
        close(fields_2[0]);
        read(fields_1[0], buffer, MAXSIZE);
        printf("from child: %s\n", buffer);
        write(fields_2[1], "hello my son\n", 13 +1);
        int status;
        wait(&status);
        break;
    }

    return 0;
}

